import axios from 'axios';
import qs from "qs";

const service = axios.create({
    baseURL:"http://me.cn/api",
    timeout:9999
})

let token = localStorage.getItem('user-token') || "{}"
token = JSON.parse(token)['value']
// http request 拦截器
service.interceptors.request.use(
    config => {
        // 定义请求头
        config.headers = {
            'Content-Type':'application/x-www-form-urlencoded',
            'authorization': token
        }
        return config;
    },
    error => {
        console.log(error)
    }
)
// http response 拦截器
service.interceptors.response.use(
    response => {
        return response.data;
    },
    error => {
        console.log(error)
    }
)
//http GET请求
export function GET(url, params = null){
    return service.get(url, {params});
}
//http POST请求
export function POST(url, params = {}){
    return service.post(url, qs.stringify({...params}));
}
//http PUT请求
export function PUT(url, params = null){
    return service.put(url, qs.stringify({...params}));
}
//http DELETE请求
export function DELETE(url, params = null){
    return service.delete(url, params);
}